﻿using System;
using System.Diagnostics;
using System.Linq;
using System.Text;

namespace Xray.Common
{
    /// <summary>
    /// provides a mechanism for your development application to communicate to the Xray viewer
    /// </summary>
    public abstract class XrayClient
    {
        /// <summary>
        /// run this to update the Xray Viewer with the latest information in the container.
        /// if nothing seems to be happen, open the debugger window, as there may be an error reported there.
        /// </summary>
        public void Update()
        {
            Model model = PopulateModel();
            using (var client = ContainerXrayServiceClient.Create())
            {
                try
                {
                    client.Update(model);
                }
                catch (Exception ex)
                {
                    Debugger.Log(1, "Xray - connection to monitor", ex.ToString());
                }
                   
            }
        }

        /// <summary>
        /// populates a model with all the information from the container, all the components it contains and
        /// their dependencies
        /// </summary>
        /// <returns>the model is returned</returns>
        protected abstract Model PopulateModel();
    }
}
